<script lang="ts" setup>
import { useSubjectStore } from '@/stores'
const subjectStore = useSubjectStore()
const setcompletion = (data) => {
  if (data.id === undefined) {
    ElMessage.error('实验未完成，请不要提交临床实验完成表')
    return
  }
  subjectStore.eliminate.id = data.id
  subjectStore.exit.id = data.id
  subjectStore.suspend.id = data.id
  subjectStore.setCompletion(data).then((code) => {
    if (code === true) {
      if (data.type === 1) subjectStore.setEliminate(subjectStore.eliminate)
      else if (data.type === 2) subjectStore.setExit(subjectStore.exit)
      else if (data.type === 3) subjectStore.setSuspend(subjectStore.suspend)
      ElMessage.success('成功')
    } else {
      ElMessage.error('失败')
    }
  })
}
const types = [
  {
    value: 1,
    label: '剔除'
  },
  {
    value: 2,
    label: '退出(脱落)'
  },
  {
    value: 3,
    label: '中止实验'
  }
]
</script>
<template>
  <el-radio-group v-model="subjectStore.completion.isCompletionExperiment">
    <el-radio :value="0">完成</el-radio>
    <el-radio :value="1">未完成 为“未完成”者，请填写以下具体原因：</el-radio>
  </el-radio-group>
  <el-table
    v-if="subjectStore.completion.isCompletionExperiment"
    :data="[subjectStore.completion]"
    :style="{ width: '100%' }"
  >
    <el-table-column label="未完成试验归类" width="180">
      <template #default="scope">
        <el-select v-model="scope.row.type" placeholder="Select">
          <el-option
            v-for="item in types"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </template>
    </el-table-column>
    <el-table-column label="日期" width="180">
      <template #default="scope">
        <el-date-picker
          v-model="scope.row.date"
          type="date"
          placeholder="日期"
          style="width: 100%"
        />
      </template>
    </el-table-column>
    <el-table-column label="未完成试验原因">
      <template #default="scope">
        <template v-if="scope.row.type === 1">
          <el-input
            v-model="subjectStore.eliminate.reason"
            placeholder="请输入"
          />
        </template>
        <template v-else-if="scope.row.type === 2">
          <el-radio-group v-model="subjectStore.exit.reason">
            <el-radio :value="0">病人自退</el-radio>
            <el-radio :value="1">医生劝退</el-radio>
          </el-radio-group>
        </template>
        <template v-else-if="scope.row.type === 3">
          <el-radio-group v-model="subjectStore.suspend.reason">
            <el-radio :value="0">研究方中止</el-radio>
            <el-radio :value="1">组织方中止</el-radio>
          </el-radio-group>
        </template>
      </template>
    </el-table-column>
    <el-table-column label="具体原因">
      <template #default="scope">
        <template v-if="scope.row.type === 1">
          <el-checkbox
            v-model="subjectStore.eliminate.misdiagnosis"
            label="误诊误纳"
          />
          <el-checkbox
            v-model="subjectStore.eliminate.meetsExclusionCriteria"
            label="符合排除标准"
          />
          <el-checkbox
            v-model="subjectStore.eliminate.untreated"
            label="全未治疗"
          />
          <el-checkbox
            v-model="subjectStore.eliminate.noDetectionRecord"
            label="全无检测记录"
          />
        </template>
        <template v-else-if="scope.row.type === 2">
          <template v-if="subjectStore.exit.reason === 0">
            <el-checkbox
              v-model="subjectStore.exit.poorTherapeuticEffect"
              label="疗效差"
            />
            <el-checkbox
              v-model="subjectStore.exit.unbearable"
              label="难耐受"
            />
            <el-checkbox
              v-model="subjectStore.exit.economicReason"
              label="经济原因"
            />
            <el-checkbox
              v-model="subjectStore.exit.refusalExplanation"
              label="拒绝说明"
            />
            <el-checkbox
              v-model="subjectStore.exit.lostFollow_up"
              label="失访"
            />
          </template>
          <template v-else-if="subjectStore.exit.reason === 1">
            <el-checkbox v-model="subjectStore.exit.sex" label="依从性差" />
            <el-checkbox
              v-model="subjectStore.exit.complications"
              label="合并症"
            />
            <el-checkbox v-model="subjectStore.exit.transfer" label="转科" />
            <el-checkbox v-model="subjectStore.exit.ae" label="不良反应" />
          </template>
        </template>
        <template v-else-if="scope.row.type === 3">
          <template v-if="subjectStore.suspend.reason === 0">
            <el-checkbox
              v-model="subjectStore.suspend.seriousAdverseReaction"
              label="严重不良反应"
            />
            <el-checkbox
              v-model="subjectStore.suspend.poorTherapeuticEffect"
              label="疗效差"
            />
            <el-checkbox
              v-model="subjectStore.suspend.programmeGrossFault"
              label="方案重大失误"
            />
            <el-checkbox
              v-model="subjectStore.suspend.implementImportantDeviations"
              label="实施重要偏差"
            />
          </template>
          <template v-else-if="subjectStore.suspend.reason === 1">
            <el-checkbox
              v-model="subjectStore.suspend.fundingReason"
              label="经费原因"
            />
            <el-checkbox
              v-model="subjectStore.suspend.managementReason"
              label="管理原因"
            />
          </template>
        </template>
      </template>
    </el-table-column>
    <el-table-column label="提交">
      <template #default="scope">
        <el-button @click="setcompletion(scope.row)">确定</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
